package com.ruoyi.web.controller.order;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.order.domain.OrderAddress;
import com.ruoyi.order.service.IOrderAddressService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单地址Controller
 * 
 * @author ruoyi
 * @date 2022-02-08
 */
@Controller
@RequestMapping("/order/orderAddress")
public class OrderAddressController extends BaseController
{
    private String prefix = "order/orderAddress";

    @Autowired
    private IOrderAddressService orderAddressService;

    @RequiresPermissions("order:orderAddress:view")
    @GetMapping()
    public String orderAddress()
    {
        return prefix + "/orderAddress";
    }

    /**
     * 查询订单地址列表
     */
    @RequiresPermissions("order:orderAddress:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderAddress orderAddress)
    {
        startPage();
        List<OrderAddress> list = orderAddressService.selectOrderAddressList(orderAddress);
        return getDataTable(list);
    }

    /**
     * 导出订单地址列表
     */
    @RequiresPermissions("order:orderAddress:export")
    @Log(title = "订单地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderAddress orderAddress)
    {
        List<OrderAddress> list = orderAddressService.selectOrderAddressList(orderAddress);
        ExcelUtil<OrderAddress> util = new ExcelUtil<OrderAddress>(OrderAddress.class);
        return util.exportExcel(list, "订单地址数据");
    }

    /**
     * 新增订单地址
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存订单地址
     */
    @RequiresPermissions("order:orderAddress:add")
    @Log(title = "订单地址", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderAddress orderAddress)
    {
        return toAjax(orderAddressService.insertOrderAddress(orderAddress));
    }

    /**
     * 修改订单地址
     */
    @RequiresPermissions("order:orderAddress:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        OrderAddress orderAddress = orderAddressService.selectOrderAddressById(id);
        mmap.put("orderAddress", orderAddress);
        return prefix + "/edit";
    }

    /**
     * 修改保存订单地址
     */
    @RequiresPermissions("order:orderAddress:edit")
    @Log(title = "订单地址", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderAddress orderAddress)
    {
        return toAjax(orderAddressService.updateOrderAddress(orderAddress));
    }

    /**
     * 删除订单地址
     */
    @RequiresPermissions("order:orderAddress:remove")
    @Log(title = "订单地址", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderAddressService.deleteOrderAddressByIds(ids));
    }
}
